﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pow
{
    class Pow
    {
        static void Main(string[] args)
        {
            //2^5
            Console.WriteLine(XpowN(5, Identitet)(2));
        }

        static int Identitet(int x)
        {
            return x;
        }
                
        static Func<int, int> XpowN(int n, Func<int, int> func)
        {
            if (n == 0)
            {
                return (x) => 1;
            }
            n--;
            Func<int,int>  resultFunc= func;
            while(n > 0)
            {
                resultFunc = Multiply(resultFunc, func);
                n--;
            }
            return resultFunc;
        }

        static Func<int,int> Multiply(Func<int, int> x, Func<int, int> y)
        {
            return (t) => { return x(t) * y(t); };
        }
    }
}
